package leetcode;

/**
 * @author tongchen
 * @create 2023-08-05 10:43
 */

public class Main {
    /**
     * 给定一个数组nums，编写一个函数将所有0移动到数组的末尾，同时保持非零元素的相对顺序
     */
    private static void moveZeros(int[] nums){
        //查询0的个数
        int count=0;
        for(int i=0;i< nums.length;++i){
            if(nums[i]==0){
                count++;
            }
        }
        //0对应的下标
        int zeroIndex=nums.length-count;
        //循环
        for(int i=0;i<zeroIndex;++i){
            if(nums[i]==0){
                int j=i+1;
                while(nums[j]==0){
                    j++;
                }
                nums[i]=nums[j];
                nums[j]=0;
            }
        }
        //select count(*) from student where gender='女' and age>18 group by class_id
        //

    }
}
